//<tm-pagination conf="paginationConf"></tm-pagination>
app.controller('baseController' ,function($scope,$http){
    //分页控件配置
    $scope.paginationConf = {
        currentPage: 1,
        totalItems: 10,
        itemsPerPage: 3,
        perPageOptions: [3, 5, 10, 20],
        onChange: function(){
            $scope.reloadList();//重新加载
        }
    };
    $scope.reloadList=function(){
        //切换页码
        $scope.findPage( $scope.paginationConf.currentPage, $scope.paginationConf.itemsPerPage);
    }
    $scope.searchEntity={};//定义搜索对象

    $scope.selectIds=[];//选中的ID集合
    //更新复选
    $scope.updateSelection = function($event, id) {
        if($event.target.checked){//如果是被选中,则增加到数组
            $scope.selectIds.push( id);
        }else{
            var idx = $scope.selectIds.indexOf(id);
            $scope.selectIds.splice(idx, 1);//删除
        }
    }
    //全选、反选
    $scope.selectAll=function ($event) {
        $scope.checkbox=$event.target.checked;
    }


    //复选框获取选中值
    $scope.updateSelection2 = function($event,id) {
        if($event.target.checked){//如果是被选中,则增加到数组
            $scope.entity.ahids.push(id);
        }else{
            var idx = $scope.selectIds.indexOf(id);
            $scope.entity.ahids.splice(idx, 1);//删除
        }
    }
    //复选框回显
    $scope.expression=function(id){
        //console.log(id);
        return $scope.entity.ahids.indexOf(id) !=-1;
    }

    //上传
    $scope.upload=function () {
        // debugger;
        var formData=new FormData();
        formData.append("multipartFile",file.files[0]);
        $http({
            method:'POST',
            url:"../file/upload.do",
            data: formData,
            headers: {'Content-Type':undefined},//anjularjs对于post和get请求默认的Content-Type header 是application/json。通过设置‘Content-Type’: undefined，这样浏览器会帮我们把Content-Type 设置为 multipart/form-data.
            transformRequest: angular.identity //通过设置 transformRequest: angular.identity ，anjularjs transformRequest function 将序列化我们的formdata object.
        }).success(
            function(response) {
                alert("上传成功");
                $scope.entity.imgurl=response.imgsrc;
            }
        );
    }

    //获取三级分类
    $scope.getByPid=function (pid) {
        return $http.get("../tbBrand/getTbItemCats/"+pid+".do");
    }

    //获取第1级分类
    $scope.getTbItemCats=function (pid) {
        $scope.getByPid(pid).success(
            function(response){
                $scope.itemlist1=response;
            }
        )
    }

    //读取二级分类
    $scope.$watch('entity.typeId1', function(newValue, oldValue) {
        // debugger;
        if(newValue != undefined){
            $scope.getByPid(newValue).success(
                function(response){
                    $scope.itemlist2=response;
                    console.log($scope.itemlist2);
                }
            )
        }
    });
    //读取三级分类
    $scope.$watch('entity.typeId2', function(newValue, oldValue) {
        if(newValue != undefined) {
            $scope.getByPid(newValue).success(
                function (response) {
                    $scope.itemlist3 = response;
                }
            )
        }
    });
});